package com.dahua.strategy.version2;

/**
 * @author sunhongguang
 * @create 2022-01-11-0:10
 */
public class CashReturn implements CashSuper {

    private double moneyCondition = 0;
    private double moneyReturn = 0;

    /**
     * 初始化时，需要输入返利条件，比如满300返100，则moneyCondition = 300,moneyReturn = 100
     * @param moneyCondition    返利条件
     * @param moneyReturn       返利值
     */
    public CashReturn(double moneyCondition, double moneyReturn) {
        this.moneyCondition = moneyCondition;
        this.moneyReturn = moneyReturn;
    }

    @Override
    public double acceptCash(double money) {
        double result = money;
        if(money >= moneyCondition){
            result = money - Math.floor(money/moneyCondition)*moneyReturn;
        }
        return result;
    }

}
